improve js debug & cleanup unused map stuff.
authortsteven4 <tsteven4@gmail.com>
Thu, 7 Dec 2017 19:29:25 +0000 (12:29 -0700)
committertsteven4 <tsteven4@gmail.com>
Thu, 7 Dec 2017 19:29:25 +0000 (12:29 -0700)
gui/map.cc
gui/map.h

index e4d3c1e767a80b59ef0f18c4d2eff299aa4324c3..9bed4a32f35aa01fd958ecc53a65be5f5d207108 100644 (file)
 #include <QApplication>
 #include <QCursor>
 #include <QFile>
+#include <QTextStream>
 
 #include <math.h>
+#include <string>
+#include <vector>
 #include "appname.h"
-#include "dpencode.h"
+
+using std::string;
+using std::vector;
 
 //------------------------------------------------------------------------
 static QString stripDoubleQuotes(const QString s) {
@@ -92,6 +97,14 @@ Map::Map(QWidget *parent,
     QString urlStr = "file:///" + baseFile;
     this->load(QUrl(urlStr));
   }
+
+#ifdef DEBUG_JS_GENERATION
+  dbgdata_ = new QFile("mapdebug.js");
+  if (dbgdata_->open(QFile::WriteOnly | QIODevice::Truncate)) {
+    dbgout_ = new QTextStream(dbgdata_);
+  }
+#endif
+
 }
 
 //------------------------------------------------------------------------
@@ -99,6 +112,16 @@ Map::~Map()
 {
   if (busyCursor_)
     QApplication::restoreOverrideCursor();
+#ifdef DEBUG_JS_GENERATION
+  if (dbgout_) {
+    delete dbgout_;
+    dbgout_ = NULL;
+  }
+  if (dbgdata_) {
+    delete dbgdata_;
+    dbgdata_ = NULL;
+  }
+#endif
 }
 //------------------------------------------------------------------------
 void Map::loadFinishedX(bool f)
@@ -115,30 +138,6 @@ void Map::loadFinishedX(bool f)
   busyCursor_ = false;
 }
 
-//------------------------------------------------------------------------
-
-static QStringList makeLiteralVar(const QString &name, const string &s)
-{
-  QStringList out;
-  out << QString("var %1 = ").arg(name);
-
-  QString ws = "\"";
-  for (unsigned int i=0; i<s.length(); i++) {
-    if (s[i] =='\\') {
-      ws += s[i];
-    }
-    ws += s[i];
-    if (ws.length() > 5120) {
-      ws += "\" + ";
-      out << ws;
-      ws = "\"";
-    }
-  }
-  ws += "\";";
-  out << ws;
-  return out;
-}
-
 //------------------------------------------------------------------------
 static QString fmtLatLng(const LatLng &l) {
   return  QString("{lat: %1, lng: %3}").arg(l.lat(), 0, 'f', 5) .arg(l.lng(), 0, 'f', 5);
@@ -155,11 +154,6 @@ void Map::showGpxData()
   connect(mclicker, SIGNAL(markerClicked(int, int )), this, SLOT(markerClicked(int, int)));
   connect(mclicker, SIGNAL(logTime(const QString &)), this, SLOT(logTime(const QString &)));
 #endif
-  // It is appreciably faster to do the encoding on the C++ side.
-  int numLevels = 18;
-  double zoomFactor = 2;
-  PolylineEncoder encoder(numLevels, zoomFactor, 0.00001);
-
 
   this->logTime("Start defining JS string");
   QStringList scriptStr;
@@ -171,17 +165,7 @@ void Map::showGpxData()
     << "var rtes = [];"
     << "var trks = [];"
     << "var idx;"
-    << "//map.enableScrollWheelZoom();"
-    << "//map.enableContinuousZoom();"
-    << "//map.addControl(new GLargeMapControl());"
-    << "//map.addControl(new GScaleControl());"
-    << "//map.addControl(new GMapTypeControl());"
-    << "//var pn = map.getPane(G_MAP_MARKER_PANE);"
-    << "//pn.style.KhtmlUserSelect='none';"
-    << "//pn.style.KhtmlUserDrag='none';"
     << "mclicker.logTimeX(\"Done prelim JS definition\");"
-    << QString("var zoomFactor = %1;").arg(zoomFactor)
-    << QString("var numLevels = %1;").arg(numLevels)
     ;
 
   mapPresent_ = true;
@@ -462,13 +446,11 @@ void Map::frameRoute(int i)
 //------------------------------------------------------------------------
 void Map::evaluateJS(const QString &s, bool upd)
 {
-QFile data("output.txt");
-if (data.open(QFile::WriteOnly | QIODevice::Append)) {
-    QTextStream out(&data);
-    out << s;
-    out << '\n';
-}
-data.close();
+#ifdef DEBUG_JS_GENERATION
+  *dbgout_ << s;
+  *dbgout_ << '\n';
+  dbgout_->flush();
+#endif
 #if HAVE_WEBENGINE
   this->page()->runJavaScript(s);
 #else
index 20dd949aa7f7761a65d481f5544cca565a13c16c..c25653f4c27e43e300fd6f3992f5b912f8fdd931 100644 (file)
--- a/gui/map.h
+++ b/gui/map.h
 #endif
 #include <QPlainTextEdit>
 #include <QTime>
+#include <QFile>
+#include <QTextStream>
 #include "gpx.h"
 
+//#define DEBUG_JS_GENERATION
+
 class QNetworkAccessManager;
 
 
@@ -98,6 +102,10 @@ class Map : public QWebView
   void routeClicked(int i);
   
  private:
+#ifdef DEBUG_JS_GENERATION
+  QFile *dbgdata_;
+  QTextStream *dbgout_;
+#endif
   QNetworkAccessManager *manager_;
   const Gpx &gpx_;
   bool mapPresent_;